package tr3dtris.game.display.ui;

import java.awt.event.ComponentEvent;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import tr3dtris.game.Game;
import tr3dtris.game.controller.Controller;
import tr3dtris.game.controller.inputMapper.DefaultInputMapper;
import tr3dtris.game.display.AbstractDisplay;
import tr3dtris.game.display.Display2d;
import tr3dtris.game.display.Display3d;
import tr3dtris.game.events.GameOverEvent;
import tr3dtris.game.listeners.GameActionsListener;
import tr3dtris.game.persistence.Options;
import tr3dtris.game.persistence.DisplayOptions;
import tr3dtris.game.persistence.Record;
import tr3dtris.game.persistence.RecordArray;

/**
 * User interface class. Used to build the main container (window) for the whole
 * application.
 * @author Luciano Mammino <loige@hotmail.com>
 * @author Andrea Mangano <kapitan0@hotmail.it>
 * @version 0.1
 * @since 0.1
 */
public class MainWindow extends JFrame implements GameActionsListener {

    /**
     * Reference to Options object
     */
    private Options options;

    /**
     * JFrame used to show info
     */
    private JFrame infoFrame;

    /**
     * JFrame used to show records
     */
    private JFrame recordsFrame;

    /**
     * Reference to the panel contained into the #recordsDialog
     */
    private RecordPanel recordPanel;

    /**
     * Reference to the 2d display system
     */
    private Display2d display2d;

    /**
     * Reference to the 3d display system
     */
    private Display3d display3d;

    /**
     * Reference to the active display
     */
    private AbstractDisplay activeDisplay;

    /**
     * Reference to a panel that displays the game logo
     */
    private LogoPanel logoPanel;

    /**
     * Reference to the game
     */
    private Game game;

    /**
     * Reference to the inputMapper used
     */
    private DefaultInputMapper inputMapper;

    /**
     * Reference to the game controller object
     */
    private Controller controller;

    /**
     * Flag setted when a game is started
     */
    private boolean firstGameStarted;

    /**
     * Constructor. Creates a new <MainWindow> with given options
     * @param options
     */
    public MainWindow(Options options) {
        //initializes graphic components (menu, buttons, etc.)
        initComponents();

        //set the minimum size of the window
        this.setMinimumSize(640,480);

        //creates the info frame
        this.infoFrame = this.createInfoFrame();

        //creates the records frame
        this.recordsFrame = this.createRecordsFrame();

        //creates the panel with the logo
        this.logoPanel = new LogoPanel();

        //creates a new display2d
        this.display2d = new Display2d();

        //creates a new display3d
        this.display3d = new Display3d();

        //creates a new game
        this.game = new Game();

        //adds the display to the game
        this.game.addDisplay(display3d);
        this.game.addDisplay(display2d);
        
        //sets the default active display
        this.activeDisplay = this.display3d;

        //sets the logoPanel as the initial contentPane of the window
        this.setContentPane(this.logoPanel);

        //creates a default input mapper
        this.inputMapper = new DefaultInputMapper(this.game.getGameActions());

        //creates a new controller for the game based on the default input mapper
        this.controller = new Controller(this.game, this.inputMapper);

        //attach the listener of the controller (for managing user input) to the
        //main window
        this.controller.attachListener(this);


        //adds listeners
        this.game.getGameEvents().addGameActionsListener(this);

        
        //sets the options
        this.options = options;
        this.setOptions();
    }

    /**
     * Checks when the window size changes and reset the size to the minimum size
     * if the new size is smaller
     * @param w minimum width
     * @param h minimum height
     */
    public void setMinimumSize(final int w, final int h)
    {
        final JFrame frame = this;
        this.addComponentListener(new java.awt.event.ComponentAdapter() {
            @Override
            public void componentResized(ComponentEvent event) {
                frame.setSize(
                Math.max(w, frame.getWidth()),
                Math.max(h, frame.getHeight()));
            }
        });
    }

    /**
     * change the contentPane of the window with the #activeDisplay
     */
    public void resetDisplay()
    {
        if(this.firstGameStarted)
        {
            this.setContentPane(this.activeDisplay);

            //TODO: hard repaint... find a better solution
            int w = this.getWidth();
            this.setSize(w+1, this.getHeight());
            this.setSize(w-1, this.getHeight());
        }
    }

    /**
     * Creates the infoDialog
     * @return
     */
    private JFrame createInfoFrame()
    {
        JFrame frame = new JFrame();
        frame.setTitle(this.getTitle() + " - About");
        frame.setResizable(false);
        frame.setContentPane(new InfoPanel());
        frame.setSize(384, 295);
        //dialog.setDefaultCloseOperation(JDialog.HIDE_ON_CLOSE);
        //this.centerDialog(dialog);
        return frame;
    }

    /**
     * Creates the records dialog
     * @return
     */
    private JFrame createRecordsFrame()
    {
        this.recordPanel = new RecordPanel(RecordArray.load());
        JFrame frame = new JFrame();
        frame.setTitle(this.getTitle() + " - Records");
        frame.setResizable(false);
        frame.setContentPane(this.recordPanel);
        frame.setSize(400, 320);
        return frame;
    }

    /**
     * Center a given dialog into the parent window
     * @param dialog
     */
    private void centerFrame(JFrame frame)
    {
        frame.setLocation(this.getLocation().x + this.getWidth()/2 - frame.getWidth()/2,
                            this.getLocation().y + this.getHeight()/2 - frame.getHeight()/2);
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        bgViewMode = new javax.swing.ButtonGroup();
        bgBlocksShape = new javax.swing.ButtonGroup();
        bgBlocksMaterialSet = new javax.swing.ButtonGroup();
        jMenuBar1 = new javax.swing.JMenuBar();
        menu_file = new javax.swing.JMenu();
        menu_file_newGame = new javax.swing.JMenuItem();
        menu_file_records = new javax.swing.JMenuItem();
        jSeparator1 = new javax.swing.JSeparator();
        menu_file_exit = new javax.swing.JMenuItem();
        jMenu2 = new javax.swing.JMenu();
        menu_options_viewMode = new javax.swing.JMenu();
        menu_options_viewMode_3d = new javax.swing.JRadioButtonMenuItem();
        menu_options_viewMode_2d = new javax.swing.JRadioButtonMenuItem();
        menu_options_blocksShape = new javax.swing.JMenu();
        menu_options_blocksShape_0 = new javax.swing.JRadioButtonMenuItem();
        menu_options_blocksShape_1 = new javax.swing.JRadioButtonMenuItem();
        menu_options_blocksShape_2 = new javax.swing.JRadioButtonMenuItem();
        menu_options_blocksShape_3 = new javax.swing.JRadioButtonMenuItem();
        menu_options_blocksMaterialSet = new javax.swing.JMenu();
        menu_options_blocksMaterialSet_0 = new javax.swing.JRadioButtonMenuItem();
        menu_options_blocksMaterialSet_1 = new javax.swing.JRadioButtonMenuItem();
        menu_options_blocksMaterialSet_2 = new javax.swing.JRadioButtonMenuItem();
        menu_options_blocksMaterialSet_3 = new javax.swing.JRadioButtonMenuItem();
        menu_info = new javax.swing.JMenu();
        menu_info_about = new javax.swing.JMenuItem();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("TREdTRIS v1.0 beta");
        setResizable(false);
        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowClosing(java.awt.event.WindowEvent evt) {
                formWindowClosing(evt);
            }
        });

        menu_file.setText("File");

        menu_file_newGame.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_N, java.awt.event.InputEvent.CTRL_MASK));
        menu_file_newGame.setText("New Game");
        menu_file_newGame.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                menu_file_newGameActionPerformed(evt);
            }
        });
        menu_file.add(menu_file_newGame);

        menu_file_records.setText("Records...");
        menu_file_records.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                menu_file_recordsActionPerformed(evt);
            }
        });
        menu_file.add(menu_file_records);
        menu_file.add(jSeparator1);

        menu_file_exit.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_Q, java.awt.event.InputEvent.CTRL_MASK));
        menu_file_exit.setText("Exit");
        menu_file_exit.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                menu_file_exitActionPerformed(evt);
            }
        });
        menu_file.add(menu_file_exit);

        jMenuBar1.add(menu_file);

        jMenu2.setText("Options");

        menu_options_viewMode.setText("View mode");

        bgViewMode.add(menu_options_viewMode_3d);
        menu_options_viewMode_3d.setText("3D");
        menu_options_viewMode_3d.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                menu_options_viewMode_3dActionPerformed(evt);
            }
        });
        menu_options_viewMode.add(menu_options_viewMode_3d);

        bgViewMode.add(menu_options_viewMode_2d);
        menu_options_viewMode_2d.setSelected(true);
        menu_options_viewMode_2d.setText("2D (debug mode)");
        menu_options_viewMode_2d.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                menu_options_viewMode_2dActionPerformed(evt);
            }
        });
        menu_options_viewMode.add(menu_options_viewMode_2d);

        jMenu2.add(menu_options_viewMode);

        menu_options_blocksShape.setText("Blocks shape");

        bgBlocksShape.add(menu_options_blocksShape_0);
        menu_options_blocksShape_0.setSelected(true);
        menu_options_blocksShape_0.setText("J3D ColorCube (no material)");
        menu_options_blocksShape_0.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                menu_options_blocksShape_0ActionPerformed(evt);
            }
        });
        menu_options_blocksShape.add(menu_options_blocksShape_0);

        bgBlocksShape.add(menu_options_blocksShape_1);
        menu_options_blocksShape_1.setText("Smooth");
        menu_options_blocksShape_1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                menu_options_blocksShape_1ActionPerformed(evt);
            }
        });
        menu_options_blocksShape.add(menu_options_blocksShape_1);

        bgBlocksShape.add(menu_options_blocksShape_2);
        menu_options_blocksShape_2.setText("Icosaedric");
        menu_options_blocksShape_2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                menu_options_blocksShape_2ActionPerformed(evt);
            }
        });
        menu_options_blocksShape.add(menu_options_blocksShape_2);

        bgBlocksShape.add(menu_options_blocksShape_3);
        menu_options_blocksShape_3.setText("Suzanne (Blender Monkey)");
        menu_options_blocksShape_3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                menu_options_blocksShape_3ActionPerformed(evt);
            }
        });
        menu_options_blocksShape.add(menu_options_blocksShape_3);

        jMenu2.add(menu_options_blocksShape);

        menu_options_blocksMaterialSet.setText("Blocks material set");

        bgBlocksMaterialSet.add(menu_options_blocksMaterialSet_0);
        menu_options_blocksMaterialSet_0.setSelected(true);
        menu_options_blocksMaterialSet_0.setText("Flatten colors");
        menu_options_blocksMaterialSet_0.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                menu_options_blocksMaterialSet_0ActionPerformed(evt);
            }
        });
        menu_options_blocksMaterialSet.add(menu_options_blocksMaterialSet_0);

        bgBlocksMaterialSet.add(menu_options_blocksMaterialSet_1);
        menu_options_blocksMaterialSet_1.setText("Wood");
        menu_options_blocksMaterialSet_1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                menu_options_blocksMaterialSet_1ActionPerformed(evt);
            }
        });
        menu_options_blocksMaterialSet.add(menu_options_blocksMaterialSet_1);

        bgBlocksMaterialSet.add(menu_options_blocksMaterialSet_2);
        menu_options_blocksMaterialSet_2.setText("Fuzzy");
        menu_options_blocksMaterialSet_2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                menu_options_blocksMaterialSet_2ActionPerformed(evt);
            }
        });
        menu_options_blocksMaterialSet.add(menu_options_blocksMaterialSet_2);

        bgBlocksMaterialSet.add(menu_options_blocksMaterialSet_3);
        menu_options_blocksMaterialSet_3.setText("UniCT (Special Mode =P)");
        menu_options_blocksMaterialSet_3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                menu_options_blocksMaterialSet_3ActionPerformed(evt);
            }
        });
        menu_options_blocksMaterialSet.add(menu_options_blocksMaterialSet_3);

        jMenu2.add(menu_options_blocksMaterialSet);

        jMenuBar1.add(jMenu2);

        menu_info.setText("Info");

        menu_info_about.setText("About...");
        menu_info_about.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                menu_info_aboutActionPerformed(evt);
            }
        });
        menu_info.add(menu_info_about);

        jMenuBar1.add(menu_info);

        setJMenuBar(jMenuBar1);

        org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(0, 651, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(0, 494, Short.MAX_VALUE)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void menu_info_aboutActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_menu_info_aboutActionPerformed
        this.centerFrame(infoFrame);
        infoFrame.setVisible(true);
    }//GEN-LAST:event_menu_info_aboutActionPerformed

    private void menu_options_viewMode_3dActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_menu_options_viewMode_3dActionPerformed
        this.options.getDisplayOptions().setViewMode(DisplayOptions.VIEWMODE_3D);
        this.activeDisplay = this.display3d;
        this.resetDisplay();
    }//GEN-LAST:event_menu_options_viewMode_3dActionPerformed

    private void menu_options_blocksShape_0ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_menu_options_blocksShape_0ActionPerformed
        this.options.getDisplayOptions().setBlocksShape(DisplayOptions.BLOCKSHAPE_COLORCUBE);
    }//GEN-LAST:event_menu_options_blocksShape_0ActionPerformed

    private void menu_options_viewMode_2dActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_menu_options_viewMode_2dActionPerformed
        this.options.getDisplayOptions().setViewMode(DisplayOptions.VIEWMODE_2D);
        this.activeDisplay = this.display2d;
        this.resetDisplay();
    }//GEN-LAST:event_menu_options_viewMode_2dActionPerformed

    private void menu_options_blocksShape_1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_menu_options_blocksShape_1ActionPerformed
        this.options.getDisplayOptions().setBlocksShape(DisplayOptions.BLOCKSHAPE_SMOOTH);
    }//GEN-LAST:event_menu_options_blocksShape_1ActionPerformed

    private void menu_options_blocksShape_2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_menu_options_blocksShape_2ActionPerformed
        this.options.getDisplayOptions().setBlocksShape(DisplayOptions.BLOCKSHAPE_ICOSAEDRIC);
    }//GEN-LAST:event_menu_options_blocksShape_2ActionPerformed

    private void menu_options_blocksShape_3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_menu_options_blocksShape_3ActionPerformed
        this.options.getDisplayOptions().setBlocksShape(DisplayOptions.BLOCKSHAPE_SUZANNE);
    }//GEN-LAST:event_menu_options_blocksShape_3ActionPerformed

    private void menu_options_blocksMaterialSet_0ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_menu_options_blocksMaterialSet_0ActionPerformed
        this.options.getDisplayOptions().setBlocksMaterial(DisplayOptions.BLOCKSMATERIAL_SOLID);
    }//GEN-LAST:event_menu_options_blocksMaterialSet_0ActionPerformed

    private void menu_options_blocksMaterialSet_1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_menu_options_blocksMaterialSet_1ActionPerformed
        this.options.getDisplayOptions().setBlocksMaterial(DisplayOptions.BLOCKSMATERIAL_WOOD);
    }//GEN-LAST:event_menu_options_blocksMaterialSet_1ActionPerformed

    private void menu_options_blocksMaterialSet_2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_menu_options_blocksMaterialSet_2ActionPerformed
        this.options.getDisplayOptions().setBlocksMaterial(DisplayOptions.BLOCKSMATERIAL_FUZZY);
    }//GEN-LAST:event_menu_options_blocksMaterialSet_2ActionPerformed

    private void menu_options_blocksMaterialSet_3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_menu_options_blocksMaterialSet_3ActionPerformed
        this.options.getDisplayOptions().setBlocksMaterial(DisplayOptions.BLOCKSMATERIAL_UNICT);
    }//GEN-LAST:event_menu_options_blocksMaterialSet_3ActionPerformed

    private void formWindowClosing(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowClosing
        this.saveOptions();
    }//GEN-LAST:event_formWindowClosing

    private void menu_file_exitActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_menu_file_exitActionPerformed
        this.saveOptions();
        System.exit(0);
    }//GEN-LAST:event_menu_file_exitActionPerformed

    private void menu_file_recordsActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_menu_file_recordsActionPerformed
        this.centerFrame(recordsFrame);
        recordsFrame.setVisible(true);
    }//GEN-LAST:event_menu_file_recordsActionPerformed

    private void menu_file_newGameActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_menu_file_newGameActionPerformed
        this.startNewGame();
    }//GEN-LAST:event_menu_file_newGameActionPerformed


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.ButtonGroup bgBlocksMaterialSet;
    private javax.swing.ButtonGroup bgBlocksShape;
    private javax.swing.ButtonGroup bgViewMode;
    private javax.swing.JMenu jMenu2;
    private javax.swing.JMenuBar jMenuBar1;
    private javax.swing.JSeparator jSeparator1;
    private javax.swing.JMenu menu_file;
    private javax.swing.JMenuItem menu_file_exit;
    private javax.swing.JMenuItem menu_file_newGame;
    private javax.swing.JMenuItem menu_file_records;
    private javax.swing.JMenu menu_info;
    private javax.swing.JMenuItem menu_info_about;
    private javax.swing.JMenu menu_options_blocksMaterialSet;
    private javax.swing.JRadioButtonMenuItem menu_options_blocksMaterialSet_0;
    private javax.swing.JRadioButtonMenuItem menu_options_blocksMaterialSet_1;
    private javax.swing.JRadioButtonMenuItem menu_options_blocksMaterialSet_2;
    private javax.swing.JRadioButtonMenuItem menu_options_blocksMaterialSet_3;
    private javax.swing.JMenu menu_options_blocksShape;
    private javax.swing.JRadioButtonMenuItem menu_options_blocksShape_0;
    private javax.swing.JRadioButtonMenuItem menu_options_blocksShape_1;
    private javax.swing.JRadioButtonMenuItem menu_options_blocksShape_2;
    private javax.swing.JRadioButtonMenuItem menu_options_blocksShape_3;
    private javax.swing.JMenu menu_options_viewMode;
    private javax.swing.JRadioButtonMenuItem menu_options_viewMode_2d;
    private javax.swing.JRadioButtonMenuItem menu_options_viewMode_3d;
    // End of variables declaration//GEN-END:variables

    private void startNewGame()
    {
        if(this.firstGameStarted)
        {
            this.game.getGameActions().restart();
        }
        else
        {
            this.game.getGameActions().start();
            this.firstGameStarted = true;
            this.resetDisplay();
        }
    }

    public void gameOverOccured(GameOverEvent event) {
        if(event.getPoints() > 0)
        {
            String name = "";
            
            name = JOptionPane.showInputDialog(this, "Insert your name if you want to store your game result");

            if(!name.equals(""))
            {
                RecordArray.add(new Record(name, event.getPoints()));
                this.recordPanel.refreshRecordList();
            }
        }
    }

        /**
     * sets the loaded options (configure option menu and window size and location)
     */
    public void setOptions()
    {
        if (this.options == null)
        {
            this.options = new Options();
            this.options.loadDefaults();
        }

        this.setLocation(this.options.getWindowOptions().getX(),
                            this.options.getWindowOptions().getY());
        this.setSize(this.options.getWindowOptions().getWidth(),
                     this.options.getWindowOptions().getHeigth());

        switch(this.options.getDisplayOptions().getViewMode())
        {
            default:
            case DisplayOptions.VIEWMODE_3D:
                this.menu_options_viewMode_3d.setSelected(true);
                this.activeDisplay = this.display3d;
                break;

            case DisplayOptions.VIEWMODE_2D:
                this.menu_options_viewMode_2d.setSelected(true);
                this.activeDisplay = this.display2d;
                break;


        }

        switch(this.options.getDisplayOptions().getBlocksMaterial())
        {
            default:
            case DisplayOptions.BLOCKSMATERIAL_SOLID:
                this.menu_options_blocksMaterialSet_0.setSelected(true);
                break;

            case DisplayOptions.BLOCKSMATERIAL_WOOD:
                this.menu_options_blocksMaterialSet_1.setSelected(true);
                break;

            case DisplayOptions.BLOCKSMATERIAL_FUZZY:
                this.menu_options_blocksMaterialSet_2.setSelected(true);
                break;

            case DisplayOptions.BLOCKSMATERIAL_UNICT:
                this.menu_options_blocksMaterialSet_3.setSelected(true);
                break;
        }

        switch(this.options.getDisplayOptions().getBlocksShape())
        {
            default:
            case DisplayOptions.BLOCKSHAPE_COLORCUBE:
                this.menu_options_blocksShape_0.setSelected(true);
                break;

            case DisplayOptions.BLOCKSHAPE_SMOOTH:
                this.menu_options_blocksShape_1.setSelected(true);
                break;

            case DisplayOptions.BLOCKSHAPE_ICOSAEDRIC:
                this.menu_options_blocksShape_2.setSelected(true);
                break;

            case DisplayOptions.BLOCKSHAPE_SUZANNE:
                this.menu_options_blocksShape.setSelected(true);
                break;
        }

    }

    /**
     * Saves the current options when closing the window
     */
    public void saveOptions()
    {
        this.options.getWindowOptions().setX(this.getLocation().x);
        this.options.getWindowOptions().setY(this.getLocation().y);
        this.options.getWindowOptions().setWidth(this.getWidth());
        this.options.getWindowOptions().setHeigth(this.getHeight());
        this.options.save();
    }

}
